package cc.rengu.igas.bsps.core.service.trans;

import cc.rengu.igas.bsps.common.enums.RespCodeEnum;
import cc.rengu.igas.bsps.core.service.base.ManageService;
import cc.rengu.igas.bsps.facade.request.BankNearByQueryRequest;
import cc.rengu.igas.bsps.facade.response.BankNearByQueryResponse;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.StringUtil;

/**
 * @author zhangxuran
 * @version 1.0
 * @date 2020.06.28
 */
public class BankNearByQueryService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        BankNearByQueryRequest bankNearbyQueryRequest = new BankNearByQueryRequest();
        ConvertUtil.convertOutput(bankNearbyQueryRequest);
        return bankNearbyQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        BankNearByQueryRequest bankNearbyQueryRequest = (BankNearByQueryRequest) request;
        String xPos = bankNearbyQueryRequest.getXpos();
        String yPos = bankNearbyQueryRequest.getYpos();
        String distance = bankNearbyQueryRequest.getDistance();
        String instId = bankNearbyQueryRequest.getHeader().getInstId();
        if (StringUtil.isEmptyOrNull(instId) || StringUtil.isEmptyOrNull(xPos) || StringUtil.isEmptyOrNull(yPos) || StringUtil.isEmptyOrNull(distance)) {
            rglog.error("附近网点查询必填性校验失败！");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
        BizResponse<BankNearByQueryResponse> bizResponse = new BizResponse<>();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        BankNearByQueryResponse bankNearByQueryResponse = new BankNearByQueryResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        /*dubbo调用电子银行内管*/
        //TODO 银行网点信息查询


        bizResponse.setResult(bankNearByQueryResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        BankNearByQueryResponse bankNearByQueryResponse = (BankNearByQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(bankNearByQueryResponse);
    }
}
